package cn.wolfcode.trip.base.domain;

import com.alibaba.fastjson.JSON;
import lombok.*;

import java.util.HashMap;
import java.util.Map;

@Setter@Getter@ToString
@AllArgsConstructor
@NoArgsConstructor
public class Region extends BaseDomain {

    private String name;

    private Region parent;

    private Integer state;
    public static final Integer STATE_NOMAL = 0; //普通
    public static final Integer STATE_COMMEND = 1; //推荐

    public Map<String,Object> toTreeView(){
        Map<String, Object> treeMap = new HashMap<>();
        treeMap.put("id",id);
        treeMap.put("text",name);
        treeMap.put("lazyLoad",true);
        if(state == STATE_COMMEND){
            treeMap.put("tags", new String[]{"推荐"});
        }
        return treeMap;
    }
    public Object getJson(){
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        map.put("name",name);
        map.put("state",state);
        if (parent != null){
            map.put("parentId",parent.getId());
            map.put("parentName",parent.getName());
        }
        return JSON.toJSONString(map);

    }


}